angular.module('App').config(['$stateProvider', '$locationProvider', '$urlRouterProvider','Config',
    function ($stateProvider, $locationProvider, $urlRouterProvider,Config) {
        var _state = $stateProvider;

        _state.state('app', {
            url: '/',
            templateUrl: 'views/common.html',
            controller: 'default',
            controllerAs: 'ctrl',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    // return $ocLazyLoad.load(['css/common.min.css']);
                }]
            }
        })
        .state('login', {
            url: '/login',
            templateUrl: 'views/login.html',
            controller: 'login',
            controllerAs: 'ctrl',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['js/login.controller.min.js']);
                }]
            }
            });

        var menu = Config['menu'];
        menu.forEach(function (item) {
            var { title, name, url=name.replace('app.',''), path, controller = 'default', controllerAs = 'ctrl', fn,files } = item;
            _state.state(name, {
                url: url+'?:arg:arg1:arg2',
                templateUrl: path,
                cache: false,
                controller: controller,
                controllerAs: controllerAs,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        document.title = title;
                        if (files) {
                            return $ocLazyLoad.load(files).then(fn);
                        }
                    }]
                }
            });
        })

        $locationProvider.html5Mode(true);
        $urlRouterProvider.otherwise(function ($injector, $location) {
            $location.otherwise=true;
        });
    }]);